/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.OpenParts.client;

/**
 * Real caller of an {@link OPCommandCallback}, so that the call to the interface implementation is done in Java, thus taking care of the method inheritance.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 09 December 2010
 */
public class OPCommandCallbackCaller {

    /**
     * The real callback to call.
     */
    protected final OPCommandCallback callback;

    /**
     * Constructor, taking the real callback in parameter.
     * 
     * @param callback
     *            the real callback. Shouldn't be null.
     */
    public OPCommandCallbackCaller(final OPCommandCallback callback) {
        assert callback != null : "parameter callback shouldn't be null";
        this.callback = callback;
    }

    /**
     * Called when the command finished successfully. Call the real callback {@link OPCommandCallback#onSuccess()} method.
     */
    public void onSuccess() {
        callback.onSuccess();
    }

    /**
     * Called if the command failed. Call the real callback {@link OPCommandCallback#onFail(OPCommandFailureReason)} method.
     * 
     * @param reason
     *            the reason for the failure of the command
     */
    public void onFail(final OPCommandFailureReason reason) {
        callback.onFail(reason);
    }

}
